#coding:utf-8

import tensorflow as tf


var =tf.Variable(tf.random_normal([3],stddev=0.1),name='var')
var2 = tf.Variable(tf.random_normal([2, 3], stddev=0.1), name='my_var')
var3 = tf.Variable(tf.random_normal([3, 3], stddev=0.1), name='my_var2')
my_initializer = tf.random_normal_initializer(mean=0, stddev=0.1)
v = tf.get_variable('my_var2', shape=[3, 3], initializer=my_initializer)


with tf.Session() as sess:
    print(var.name)
    print (var2.name)
    print (var3.name)
    tf.initialize_all_variables().run()
    print(var.eval())

    for v in tf.all_variables():
        print(v.eval())

    print('----------------------')

    print(v.eval())

    with tf.variable_scope('layer1'):
        w = tf.get_variable('v11', shape=[2, 3], initializer=my_initializer)
        tf.initialize_all_variables().run()
        sess.run(w)
        print(w.name)
        print(w.eval())

    with tf.variable_scope('layer2'):
        w = tf.get_variable('v11', shape=[2, 3], initializer=my_initializer)
        tf.initialize_all_variables().run()
        sess.run(w)
        print(w.name)
        print(w.eval())
